﻿@using TinyForum.Web.Extensions;
@using TinyForum.Web.Extensions.Mvc;
@model TinyForum.Web.Proxies.ServiceReference.AccountDataObject
@{
    ViewBag.Title = string.Format("My Account - {0}", Site.Settings.SiteTitle);
}
<h2>@string.Format("{0} - My Account", Model.UserName)</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/tinyforum.validate.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        var postUrl = '@Url.Action("UpdateAccount", "Account")';
        $("#submit").attr({ disabled: false });
        $("#updateAccountForm").submit(function (e) {
            e.preventDefault();
            if ($(this).valid()) {
                $("#submit").attr({ disabled: true });
                var displayName = $("#DisplayName").val();
                var email = $("#Email").val();
                $.ajax(
                {
                    type: 'POST',
                    url: postUrl,
                    data: { displayName: displayName, email: email },
                    success: function (jsonData) {
                        $("#dlgContent").text(jsonData);
                        $("#dlg").dialog({
                            modal: false,
                            height: 230,
                            width: 350,
                            title: 'Update Account',
                            buttons: {
                                OK: function () {
                                    $(this).dialog("close");
                                }
                            },
                            close: function () {
                                $("#submit").attr({ disabled: false });
                            }
                        });
                    }
                });
            }
        });
    })
</script>
    <fieldset>
        <legend>Account Information</legend>
        <table id="accountInformation">
            <tr>
                <td class="imageCell">
                    @{
    if (string.IsNullOrEmpty(Model.Avatar))
    { 
                        <img src="@Url.Image("avatar.gif")" alt="Avatar" width="150px" height="150px"/>
    }
    else
    { 
                        <img src="@Url.Image(Model.Avatar)" alt="Avatar" />
    }
                    }
                    <br />
                    <input type="button" value="Change Avatar" />
                </td>
                <td class="detailsCell">
@using (Html.BeginForm("UpdateAccount", "Account", FormMethod.Post, new { id = "updateAccountForm" }))
{ 
    @Html.ValidationSummary(true)
                    <table>
                        <tr>
                            <td class="titleCell">
                                ID
                            </td>
                            <td>@Model.ID
                            </td>
                        </tr>
                        <tr>
                            <td class="titleCell">
                                User Name
                            </td>
                            <td>@Model.UserName
                            </td>
                        </tr>
                        <tr>
                            <td class="titleCell">
                                Display Name
                            </td>
                            <td>@Html.EditorFor(m => m.DisplayName)
                                @Html.ValidationMessageFor(m => m.DisplayName)
                            </td>
                        </tr>
                        <tr>
                            <td class="titleCell">
                                Email
                            </td>
                            <td>@Html.EditorFor(m => m.Email)
                                @Html.ValidationMessageFor(m => m.Email)
                            </td>
                        </tr>
                        <tr>
                            <td class="titleCell">
                                Date Joined
                            </td>
                            <td>@Model.DateJoined.ToLongDateString()
                            </td>
                        </tr>
                        @*<tr>
                            <td class="titleCell">
                                Pwd. Question
                            </td>
                            <td>@Html.EditorFor(m => m.PasswordQuestion)
                                @Html.ValidationMessageFor(m => m.PasswordQuestion)
                            </td>
                        </tr>
                        <tr>
                            <td class="titleCell">
                                Pwd. Answer
                            </td>
                            <td>@Html.EditorFor(m => m.PasswordAnswer)
                                @Html.ValidationMessageFor(m => m.PasswordAnswer)
                            </td>
                        </tr>*@
                        <tr>
                            <td class="titleCell">
                                Is Locked
                            </td>
                            <td>@Html.DisplayFor(m => m.IsLocked)
                            </td>
                        </tr>
                        <tr>
                            <td class="titleCell">
                                Is Approved
                            </td>
                            <td>@Html.DisplayFor(m => m.IsApproved)
                            </td>
                        </tr>
                        <tr>
                            <td class="titleCell">
                            </td>
                            <td>
                                <input type="submit" value="Update Account" id="submit" />
                            </td>
                        </tr>
                    </table>
}
                </td>
            </tr>
        </table>
    </fieldset>

<div id="dlg" style="display: none">
    <p id="dlgContent" />
</div>

@*<fieldset>
        <legend>AccountDataObject</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.Avatar)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Avatar)
            @Html.ValidationMessageFor(model => model.Avatar)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DateJoined)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DateJoined)
            @Html.ValidationMessageFor(model => model.DateJoined)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DateLastLogon)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DateLastLogon)
            @Html.ValidationMessageFor(model => model.DateLastLogon)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DisplayName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DisplayName)
            @Html.ValidationMessageFor(model => model.DisplayName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Email)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Email)
            @Html.ValidationMessageFor(model => model.Email)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.IsAdmin)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.IsAdmin)
            @Html.ValidationMessageFor(model => model.IsAdmin)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Password)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Password)
            @Html.ValidationMessageFor(model => model.Password)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.UserName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.UserName)
            @Html.ValidationMessageFor(model => model.UserName)
        </div>

        @Html.HiddenFor(model => model.ID)

        <div class="editor-label">
            @Html.LabelFor(model => model.IsOnline)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.IsOnline)
            @Html.ValidationMessageFor(model => model.IsOnline)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.IsLocked)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.IsLocked)
            @Html.ValidationMessageFor(model => model.IsLocked)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.IsApproved)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.IsApproved)
            @Html.ValidationMessageFor(model => model.IsApproved)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DateLastLocked)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DateLastLocked)
            @Html.ValidationMessageFor(model => model.DateLastLocked)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DateLastPasswordChanged)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DateLastPasswordChanged)
            @Html.ValidationMessageFor(model => model.DateLastPasswordChanged)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.PasswordQuestion)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.PasswordQuestion)
            @Html.ValidationMessageFor(model => model.PasswordQuestion)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.PasswordAnswer)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.PasswordAnswer)
            @Html.ValidationMessageFor(model => model.PasswordAnswer)
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>*@

